package com.ssm.blog.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.blog.dao.DiaryDAO;
import com.ssm.blog.pojo.Diary;
import com.ssm.blog.pojo.criteria.DiaryCriteria;
import com.ssm.blog.service.DiaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DiaryServiceImpl implements DiaryService {
    @Autowired
    private DiaryDAO diaryDAO;

    @Override
    public void addDiary(Diary diary) {
        diaryDAO.addDiary(diary);
    }

    @Override
    public PageInfo<Diary> getDiaryList(DiaryCriteria criteria, int page, int pageSize) {
        PageHelper.startPage(page,pageSize,"id desc");
        List<Diary> diaryList=diaryDAO.getDiaryList(criteria);
        PageInfo<Diary> pageInfo=new PageInfo<>(diaryList);
        return pageInfo;
    }

    @Override
    public void deleteDiary(Integer id) {
        diaryDAO.deleteDiary(id);
    }
}
